package com.cgbl.service.ui

import android.graphics.Color
import android.os.Bundle
import android.widget.ImageView
import android.widget.TextView
import androidx.recyclerview.widget.LinearLayoutManager
import com.alibaba.android.arouter.facade.annotation.Route
import com.cgbl.service.BR
import com.cgbl.service.R
import com.cgbl.service.adapter.TeamMemberAdapter
import com.cgbl.service.databinding.AppActivityAddTeamBinding
import com.cgbl.service.databinding.AppActivityCreateOrderBinding
import com.cgbl.service.pop.FilterPop
import com.cgbl.service.view.CGTimePickerBuilder
import com.cgbl.service.view.CGTimePickerView
import com.cgbl.service.vm.AddTeamViewModel
import com.cgbl.service.vm.CreateOrderViewModel
import com.lxj.xpopup.XPopup
import com.robot.base.base.activity.GLBaseActivity
import com.robot.base.configs.AppConstants
import java.util.*

@Route(path = AppConstants.Router.Project.A_CREATE_ORDER)
class CreateOrderActivity : GLBaseActivity<AppActivityCreateOrderBinding, CreateOrderViewModel>() {

    private lateinit var pvTime: CGTimePickerView

    override fun initContentView(savedInstanceState: Bundle?): Int =
        R.layout.app_activity_create_order

    override fun initVariableId(): Int = BR.viewModel

    override fun initComponents() {
        initTiterBar()
        initTimePicker()
    }

    private fun initTiterBar() {
        val titleView = findViewById<TextView>(R.id.tv_title)
        val backView = findViewById<ImageView>(R.id.iv_back)
        titleView?.text = "生成订单"
        backView?.setOnClickListener { finish() }
    }

    override fun initViewObservable() {
        viewModel.uc.showStartTimeCommand.observe(this) {
            pvTime.show()
        }
    }

    private fun initTimePicker() {
        //控制时间范围(如果不设置范围，则使用默认时间1900-2100年，此段代码可注释)
        //因为系统Calendar的月份是从0-11的,所以如果是调用Calendar的set方法来设置时间,月份的范围也要是从0-11
        val selectedDate: Calendar = Calendar.getInstance()
        //时间选择器
        pvTime = CGTimePickerBuilder(
            this
        ) { date, v -> //选中事件回调
            // 这里回调过来的v,就是show()方法里面所添加的 View 参数，如果show的时候没有添加参数，v则为null
            /*btn_Time.setText(getTime(date));*/
//            val btn: Button = v as Button
//            btn.setText(getTime(date))
        }.setLayoutRes(
                R.layout.app_pickerview_birthday
            ) { v ->
//                val tvSubmit = v.findViewById(R.id.tv_finish) as TextView
//                val ivCancel = v.findViewById(R.id.iv_cancel) as ImageView
//                tvSubmit.setOnClickListener {
//                    pvTime.returnData()
//                    /*pvTime.dismiss();*/
//                }
//                ivCancel.setOnClickListener { /*pvTime.dismiss();*/ }
            }.setType(booleanArrayOf(true, true, true, false, false, false))
            .setLabel("", "", "", "", "", "") //设置空字符串以隐藏单位提示   hide label
            .setDividerColor(Color.WHITE).setContentTextSize(14)
            .setTextColorCenter(Color.parseColor("#424242"))
            .setTextColorOut(Color.parseColor("#7e7e7e")).setDate(selectedDate)
            .setOutSideColor(0x00000000).setLineSpacingMultiplier(3f).setItemVisibleCount(4)
            .setOutSideCancelable(false).isDialog(true).build()
        pvTime.setKeyBackCancelable(false) //系统返回键监听屏蔽掉
    }

}